#include <iostream>
#include<sys/time.h>
#include<unistd.h>
using namespace std;
int* a, * b;
const int n = 300000;//规定是偶数，方便二路算法计算
void recursion(int n)
{
    if (n == 1)
        return;
    else
    {
        for (int i = 0; i < n; i++)
            a[i] += a[n - i - 1];
        n = n / 2;
        recursion(n);
    }
}


int main()
{
    a = new int [n];
    b = new int[n];
    //初始化记录数据的数组
    for (int i = 0; i < n; i++)
    {
        a[i] = rand() % 100;
        b[i] = a[i];
    }


    //递归算法
    struct timeval start3;
    struct timeval end3;
    gettimeofday(&start3, NULL);
    recursion(n);
    gettimeofday(&end3, NULL);
    cout << "递归算法耗时: " << end3.tv_sec - start3.tv_sec << "ms" << endl;



}